# Contributor: Andy Li <andy@onthewings.net>
# Maintainer: Andy Li <andy@onthewings.net>
pkgname=ocaml-ptmap
_pkgname=ptmap
pkgver=2.0.5
pkgrel=3
pkgdesc="Maps over integers implemented as Patricia trees"
url="https://github.com/backtracking/ptmap"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	dune
	ocaml
	ocaml-findlib
	ocaml-stdlib-shims
	ocaml-seq-dev
	"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/backtracking/ptmap/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	make all
}

check() {
	make test
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml

	# There's just a readme and changelog.
	rm -Rf "$pkgdir"/usr/doc
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
6815ee977cb9a4c5088af8dfb7d8055c8d35870ceb4e95f658fbdc50405495bea75a8755442dc6f7345d2e9021c3b96d14883603759baf267feced9cd5ba5202  ocaml-ptmap-2.0.5.tar.gz
"
